package com.md24housecall.adapter;

import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.md24housecall.activity.R;
import com.md24housecall.model.CategoryPartner;

public class PartnerCategoryAdapter extends BaseAdapter {
	private List<CategoryPartner> listCategories;
	private Context mContext;
	private int[] bgResource={R.drawable.btn_category1,R.drawable.btn_category2,R.drawable.btn_category3,R.drawable.btn_category4};
	
	public PartnerCategoryAdapter(Context context,List<CategoryPartner> listCategories){
		this.listCategories=listCategories;
		mContext=context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listCategories.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View rowView = convertView;
		ViewHolder viewHolder;
		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.partner_category_item, null);
			viewHolder = new ViewHolder();
			viewHolder.txvCategory = (TextView) rowView.findViewById(R.id.txvCategoryPartner);
			rowView.setTag(viewHolder);
		}
		try{
			rowView.setBackgroundResource(bgResource[position%bgResource.length]);
		}catch(Exception e){
			e.printStackTrace();
		}
		viewHolder = (ViewHolder) rowView.getTag();
		viewHolder.txvCategory.setText(listCategories.get(position).getName());
		return rowView;
	}
	
	public static class ViewHolder {
		public TextView txvCategory;
	}

}
